
package com.zsrt.examsystem.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.zsrt.examsystem.dao.StudentMethodDao;
import com.zsrt.examsystem.stduententity.Student;

/**
 * 学生的所有方法接口的实现
 * @author jmj
 * @date 2017年4月23日
 * @time 下午4:05:47
 */
public class StudentMethodDaoImpl implements StudentMethodDao{

	/**
	 * 查询本人信息
	 */
	@Override
	public void searchPersonalInformation( List<Student> students, String ownName) {

        //students = MethodUtil.studentMessage();
		for(Student student : students){
			String name = student.getName();
			if(name.equals(ownName)){
				System.out.println(student);
			}
		}
	}

	/**
	 * 查询本市总分状元
	 */
	@Override
	public Student checkMaxScoreByHuji(List<Student> students, String ownHuji) {

		Student student = new Student();
		int score =0;
		for(Student student1 : students){
			String huji = student1.getHuji();
			if(huji.equals(ownHuji)){
				int totalScore = student1.getChineseScore()+student1.getEnglishScore()+student1.getMathScore();
				if(totalScore>score){
					score = totalScore;
					student =student1;
				}
			}
		}
		return student;
	}

	/**
	 * 查询各个省份的状元
	 */
	@Override
	public List<Student> checkMaxEveryCity(List<Student> students) {

		List<Student> sList = new ArrayList<Student>();
		int score = 0;
		Student student = new Student();
		Student student1 = new Student();
		/*//查询安徽省的状元
		String city = "安徽省";
		for(int index = 0;index<students.size();index++){
			student = students.get(index);
			String huji = student.getHuji();
			if(huji.equals(city)){
				int totalScore = student.getChineseScore()+student.getEnglishScore()+student.getMathScore();
				if(totalScore>score){
					score = totalScore;
				}
			}
		}*/
		//查询各个省的状元
		String[] citys = {"四川省","安徽省","广东省"};
		for(int i =0;i<citys.length;i++){
			for(int index=0;index<students.size();index++){
				
				student = students.get(index);
				String city = student.getProvince();
				
				if(city.equals(citys[i])){
					int totalScore = student.getChineseScore()+student.getEnglishScore()+student.getMathScore();
					if(totalScore>score){
						score = totalScore;
						student1 = student;
					}
				}
			}
			sList.add(student1);
			score =0;
		}
		
		
		return sList;
	}

	/**
	 * 查询指定城市的状元
	 */
	@Override
	public Student checkMaxOfCity(String city, List<Student> students) {

		Student student = new Student();
		int score =0;
		for(Student student1 : students){
			String huji = student1.getHuji();
			if(huji.equals(city)){
				int totalScore = student1.getChineseScore()+student1.getEnglishScore()+student1.getMathScore();
				if(totalScore>score){
					score = totalScore;
					student =student1;
				}
			}
		}
		return student;
		
	}

	/**
	 * 查询各个省份200-300分的总人数并由高到低排列显示
	 */
	@Override
	public void checkScoreByProvince(List<Student> students,int lowScore,int highScore) {
		

		List<Student> sList = new ArrayList<Student>();
		Student student = new Student();
		/*
		Collections.sort(students);
		for(Student s: students){
			System.out.println(s);
		}
		*/
		int count=0;
		Collections.sort(students);
		String[] citys = {"四川省","安徽省","广东省"};
		
		for(int i=0;i<citys.length;i++){
			for(int index=0;index<students.size();index++){
				
				student = students.get(index);
				String city = student.getProvince();
				
				if(city.equals(citys[i])){
					int totalScore = student.getChineseScore()+student.getEnglishScore()+student.getMathScore();
					if(totalScore>lowScore && totalScore<highScore){
						count++;
						sList.add(student);
						System.out.println(student);
					}
				}
			}
			System.out.println(count);
			count=0;
			
		}
			
	}

	/**
	 * 查询各个省份过300分的总人数并由低到高排列显示
	 */
	@Override
	public void checkScoreByProvinceAsc(List<Student> students, int newScore) {
		List<Student> sList = new ArrayList<Student>();
		Student student = new Student();
		/*
		Collections.sort(students);
		for(Student s: students){
			System.out.println(s);
		}
		*/
		int count=0;
		Collections.sort(students);
		String[] citys = {"四川省","安徽省","广东省"};
		
		for(int i=0;i<citys.length;i++){
			for(int index=0;index<students.size();index++){
				
				student = students.get(index);
				String city = student.getProvince();
				
				if(city.equals(citys[i])){
					int totalScore = student.getChineseScore()+student.getEnglishScore()+student.getMathScore();
					if(totalScore>newScore ){
						count++;
						sList.add(student);
					}
				}
			}
			System.out.println(citys[i]+"有"+count+"个分数大于"+newScore);
			count=0;
		}
		
		for(Student s: sList){
			System.out.println(s);
		}
		
		
		
	}

	
	
}
